package com.tjnmt.togo.utils;


import android.app.Activity;
import android.app.ActivityManager;
import android.content.Context;

import java.util.List;

/*
 *管理服务的工具类。
 */
public class ServiceUtil {
        private static final ActivityManager activityManager;

        static {
            activityManager = (ActivityManager)ApplicationUtils.getContext().getSystemService(Context.ACTIVITY_SERVICE);
        }
        //判断轨迹服务是否正在运行的方法。
        public static boolean isLocating(){
            List<ActivityManager.RunningServiceInfo> serviceInfoList = activityManager.getRunningServices(100);
            int length = serviceInfoList.size();
            for(int i = 0;i < length;i++){
                if("com.baidu.trace.LBSTraceService".equals(serviceInfoList.get(i).service.getClassName())){
                    return true;
                }
            }
                return false;
        }

        public static List<ActivityManager.RunningServiceInfo> getServiceInfoList(int maxNum){
                List<ActivityManager.RunningServiceInfo> serviceInfoList = activityManager.getRunningServices(maxNum);
                return serviceInfoList;
        }
}
